# -*- coding: utf-8 -*-
# @Time : 2021/9/10 11:45
# @Author : 阿怪
# @Email : scg@gmail.com
# @File : CRM-ST-ZNX-12.py
# @Project : crm自动化测试项目实战
'''验证站内信的删除功能'''

from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep
from selenium.webdriver.common.alert import Alert  # 把弹窗封装成类Alert

driver = webdriver.Chrome()
cookie = {'name': 'PHPSESSID', 'value': '0onrpth7nsd6mbi1hfgi99o2b1'}  # 获取到cookid
driver.get('http://192.168.1.140/')  # 访问服务器
driver.add_cookie(cookie)
driver.get('http://192.168.1.140/crm3/index.php?m=message')
#进入站内信首页


#1.点击写信进入编辑界面
add_send_locator = (By.ID,'send')  #写信定位器
operation_locator = (By.CSS_SELECTOR,'body > div.container > div.row > div > div.span12.nav > div > ul > li.nav.pull-left > div > a')  #批量操作定位器
delete_locator = (By.ID,'delete_receive')  #删除定位器

driver.find_element(*add_send_locator).click()
sleep(3)

#2.输入信息啥的
text_locator = (By.NAME,'content')   #内容输入框定位器
submit_locator = (By.NAME,'submit')    #发送按钮定位器

driver.find_element(By.CSS_SELECTOR,'#ta1 > input').click()    #点击全选
driver.find_element(*text_locator).send_keys('我是测试')
driver.find_element(*submit_locator).click()

#3.去删除刚刚添加的信息
check_locator = (By.CSS_SELECTOR,'#form1 > table > tbody > tr:nth-child(1) > td:nth-child(1) > input')
driver.find_element(*check_locator).click()
driver.find_element(*operation_locator).click()
driver.find_element(*delete_locator).click()
alert = Alert(driver)  # 实例化Alert
sleep(3)
alert.accept()
sleep(3)
driver.quit()


#删除之后没有删除成功提醒，断言的时候需要考虑怎么断言。